#define LoadSaveFile
/* Save/load a file using INI format.
 * argument0 operation 0 for load, save otherwhise. If load then only first 2 paramteres are 
 * important.
 * argument1 character name for save operation, filename for load operation
 * argument2 stats
 * argument3 spells 
 * argument4 checkpoint number
 * @see CharacterInit
 */
if(argument0 == 0) {
    file = ini_open(argument[1]);
    with(Character) {
        // destroy all instances of character object.
        instance_destroy();
    }
    /* the last value corresponds to a character with 10 to all stats and 
     * class 0.
     */
    stats = ini_read_real('Character', 'stats', 10570);
    variable_global_set('stats', stats);
    /* the last value corresponds to a character of level 1 with only
     * Fire Bolt spell available.
     */
    spells = ini_read_real('Character', 'spells', 1026);
    variable_global_set('spells', spells);
    /* Artanis is the default name of the character */
    name = ini_read_string('Character', 'name', 'Artanis');
    variable_global_set('name', name);
    /* Default value is the first checkpoint of the game (new game) */
    check = ini_read_string('Character', 'checkpoint', '0TutorialLevel');
    variable_global_set('check', real(string_copy(check, 1, 2)));
    target_room = string_copy(check, 3, string_length(check) - 2);
    idx = 0;
    while((idx < global.MAX_ROOMS) && (room_get_name(idx) != target_room)) {
        idx += 1;
    }
    //the code in the target room checks this value in order to call CharacterInit
    variable_global_set('new_char', true);
    //move to the target room
    if(idx < global.MAX_ROOMS) {
        room_goto(idx);
    }
} else {
    file = ini_open(argument[1] + '_save.ini');
    /* Saving character stuff. No additional things are required as the
     * game can continue normally from this point.
     */
    ini_write_string('Character', 'name', argument1);
    ini_write_real('Character', 'stats', argument2);
    ini_write_real('Character', 'spells', argument3);
    ini_write_string('Character', 'checkpoint', argument4);
}
ini_close();

